/****** Object:  View [dbo].[Report_Users_TopPostUsers_View]    Script Date: 11/26/2012 01:03:35 ******/
ALTER VIEW [dbo].[Report_Users_TopPostUsers_View]      
AS      
SELECT    
 Users.Username    
 ,ISNULL(postsTMP.TotalPosts,0) TotalPosts      
  ,Users.Fullname      
  ,Users.Email      
  ,Users.[Address]      
  ,Users.Phone  
  ,postsTMP.Times  
FROM Users      
 RIGHT JOIN ( SELECT COUNT(Posts.PostID) TotalPosts      
      ,Posts.Username  
      --,YEAR(TimeCreated) years
      ,convert(varchar(7), TimeCreated, 111) Times
    FROM Posts      
    WHERE Posts.IsDeleted = CAST(0 AS BIT)      
    GROUP BY Posts.Username
			,TimeCreated 
     ) AS postsTMP     
  ON (Users.Username = postsTMP.Username)
--WHERE postsTMP.years is not null



